class Animal {
    public String name;
    public int age;

    public Animal() {
    }

    public Animal(String name, int age) {
        this.name = name;
        this.age = age;
    }

    @Override
    public String toString() {
        return this.name + "{" +
                "name='" + name + '\'' +
                ", age=" + age +
                '}';
    }

    public void Eat() {
        System.out.println(this.name + "name" + "在吃饭！");
    }
}

class Dog extends Animal {

    public Dog() {

    }

    public Dog(String name, int age) {
        super(name, age);
    }

    public void Eat() {
        System.out.println(this.name + "在狗粮！");
    }


}

class Cat extends Animal {
    public Cat() {
    }

    public Cat(String name, int age) {
        super(name, age);
    }

    @Override
    public void Eat() {
        System.out.println(this.name + "正在吃猫粮！！");
    }

    public void miaomiao() {
        System.out.println(this.name + "正在喵喵叫！！");
    }
}

public class Test {
    public static void main(String[] args) {
        Animal animal = new Dog("媛媛", 19);
        Dog dog = (Dog) animal;
        dog.Eat();
        if (animal instanceof Cat) {
            Cat cat = (Cat) animal;
            cat.miaomiao();
        }
        else {
            System.out.println("我理解啦！！！");
        }
    }

    public static void eatFunc(Animal animal) {
        animal.Eat();
    }

    public static void main2(String[] args) {
        Dog dog = new Dog("楚路曼", 2);
        eatFunc(dog);

        Cat cat = new Cat("李毅朝", 21);
        eatFunc(cat);
    }
}

//        Animal animal = new Dog("媛媛",20);
//        animal.Eat();
//        System.out.println(animal.toString());
//
//        Animal animal1 = new Cat("咪咪",5);
//        animal1.Eat();
//        System.out.println(animal1.toString());
//    }
//}
//    public static void func(Animal animal) {
//
//    }
////3.返回值 向上转型
//    public static Animal func2(){
//        Dog dog = new Dog("媛媛",20);
//        return dog;
//    }
//
////    2.方法的参数，传参的时候  进行向上转型
//    public static void main(String[] args) {
//        Dog dog = new Dog("媛媛",20);
//        func(dog);
//
//        Animal animal = func2();
//    }
//}

//1.直接赋值
//    public static void main(String[] args) {
//        Animal animal = new Dog("媛媛",18);
//        animal.Eat();
//    }
//
//}
